<template>
  <div class="audit">
    <!--tab-->
    <van-tabs v-model="active" swipeable color="#1989fa">
      <van-tab title="备案处置" name="1"></van-tab>
      <van-tab title="核查工具" name="2"></van-tab>
    </van-tabs>
    <!--tab-->
    <!--备案处置-->
    <div v-show="active == '1'">
      <!-- 基本信息 -->
      <infoView v-if="formDataType" :formData="formData" @checkBtn="checkBtn1"></infoView>
      <!-- 基本信息 -->
      <div class="czInfo">
        <div>相关处置</div>
      </div>
      <van-field
        v-if="isInAndOuts == 2 || isInAndOuts == 3"
        input-align="right"
        name="radio"
        label="现场核酸采样"
      >
      <template #label>
        现场核酸采样
        <span v-show="formData.worker_wj" style="color: #58be6a;font-size:14px;">(已核验)</span>
      </template>
        <template #input>
          <van-radio-group v-model="resultsData.hscy" :disabled="formData.worker_type !== 'WJ'" direction="horizontal">
            <van-radio name="1">是</van-radio>
            <van-radio name="2">否</van-radio>
          </van-radio-group>
        </template>
      </van-field>
      <div class="trip">
        <van-field
          v-if="isInAndOuts == 2 || isInAndOuts == 3"
          input-align="right"
          name="radio"
          label="体温状况"
        >
        <template #label>
          体温状况
          <span v-show="formData.worker_wj" style="color: #58be6a;font-size:14px;">(已核验)</span>
        </template>
          <template #input>
            <van-radio-group v-model="resultsData.temperature" :disabled="formData.worker_type !== 'WJ'" direction="horizontal">
              <van-radio name="1">体温正常</van-radio>
              <van-radio name="2">体温异常</van-radio>
            </van-radio-group>
          </template>
        </van-field>
      </div>
      <van-field
        v-if="isInAndOuts == 2 || isInAndOuts == 3"
        input-align="right"
        name="radio"
        label="现场货物检验"
      >
      <template #label>
        现场货物检验
        <span v-show="formData.worker_jt" style="color: #58be6a;font-size:14px;">(已核验)</span>
      </template>
        <template #input>
          <van-radio-group v-model="resultsData.type" :disabled="formData.worker_type !== 'JT'" direction="horizontal">
            <van-radio name="1">冷链</van-radio>
            <van-radio name="2">非冷链</van-radio>
          </van-radio-group>
        </template>
      </van-field>
      <!--<van-field v-if="isInAndOuts == 2 || isInAndOuts == 3" input-align="right" name="radio" label="健康证明">-->
      <!--  <template #input>-->
      <!--    <van-radio-group v-model="resultsData.worker_jkzm" direction="horizontal">-->
      <!--      <van-radio name="1" >有</van-radio>-->
      <!--      <van-radio name="2" >无</van-radio>-->
      <!--    </van-radio-group>-->
      <!--  </template>-->
      <!--</van-field>-->
      <van-field name="radio" input-align="right" label="管控处置情况">
        <template #label>
          管控处置情况
          <span v-show="formData.worker_wj" style="color: #58be6a;font-size:14px;">(已核验)</span>
        </template>
        <template #input>
          <van-radio-group v-model="radio" :disabled="formData.worker_type !== 'WJ'" direction="horizontal">
            <van-radio name="1">放行</van-radio>
            <!-- <van-radio name="2">劝返</van-radio> -->
            <van-radio name="3">隔离</van-radio>
          </van-radio-group>
        </template>
      </van-field>
      <van-field
        v-if="radio == '2'"
        v-model="message"
        rows="2"
        autosize
        label="劝返原因"
        type="textarea"
        maxlength="50"
        placeholder="请输入劝返原因"
        show-word-limit
      />
      <!-- <van-field v-if="radio == '3'" name="radio" label="隔离方式"> -->
      <!-- <template #input> -->
      <!-- <van-radio-group v-model="isolation" direction="horizontal"> -->
      <!--      <van-radio name="0">居家隔离</van-radio>-->
      <!--      <van-radio name="1">集中隔离</van-radio>-->
      <!--    </van-radio-group>-->
      <!--  </template>-->
      <!--</van-field>-->
      <!--<div v-if="radio == '3' && isolation == '0'">-->
      <!--  <div>-->
      <!--    <van-field input-align="right"-->
      <!--               label="家属姓名"-->
      <!--               v-model="resultsData.familyMembers"-->
      <!--               name="pattern"-->
      <!--               placeholder="请输入家属姓名"-->
      <!--               :rules="[{ required: true }]"-->
      <!--    />-->
      <!--    <van-field input-align="right"-->
      <!--               label="家属电话"-->
      <!--               v-model="resultsData.familyMembersPhone"-->
      <!--               name="pattern"-->
      <!--               placeholder="请输入家属电话"-->
      <!--               :rules="[{ pattern,required: true }]"-->
      <!--    />-->
      <!--  </div>-->
      <!--</div>-->
      <!--<div v-if="radio == '3' && isolation == '1'">-->
      <!--  <div class='concentrated'>-->
      <!--    <van-field name="radio" label="集中隔离原因">-->
      <!--      <template #input>-->
      <!--        <van-radio-group v-model="resultsData.concentratedType" direction="horizontal" >-->
      <!--          <van-radio name="0">重点管控区</van-radio>-->
      <!--          <van-radio name="1">无法居家检测</van-radio>-->
      <!--        </van-radio-group>-->
      <!--      </template>-->
      <!--    </van-field>-->
      <!--    <van-field input-align="right"-->
      <!--               label="送达体温"-->
      <!--               v-model="resultsData.concentratedTw"-->
      <!--               name="pattern"-->
      <!--               placeholder="请输入送达体温"-->
      <!--               :rules="[{ required: true }]">-->
      <!--      <template #right-icon>-->
      <!--        ℃-->
      <!--      </template>-->
      <!--    </van-field>-->
      <!--  </div>-->
      <!--</div>-->
      <van-field
        readonly
        clickable
        input-align="right"
        label="请选择关卡"
        :value="taxOutpost"
        placeholder="请选择关卡"
        @click="showTaxOutpost = true"
      />
      <van-popup v-model="showTaxOutpost" round position="bottom">
        <van-picker
          show-toolbar
          value-key="lable"
          :columns="taxOutpostcolumns"
          @cancel="showTaxOutpost = false"
          @confirm="onTaxOutpost"
        />
      </van-popup>
      <!--提交-->
      <!-- 卫建 -->
      <van-button v-if="formData.worker_type == 'WJ' && !formData.worker_wj" type="primary" block @click="submit" style="margin-top: 1rem;">确认提交</van-button>
      <!-- 交通 -->
      <van-button v-if="formData.worker_type == 'JT' && !formData.worker_jt" type="primary" block @click="submit" style="margin-top: 1rem;">确认提交</van-button>
      <!-- 公安 -->
      <van-button v-if="formData.worker_type == 'GA' && !formData.worker_ga" type="primary" block @click="submit" style="margin-top: 1rem;">确认提交</van-button>
      <!--提交-->
    </div>
    <!--备案处置-->

    <!-- 小工具 -->
    <div v-show="active == 2">
      <toolView v-if="formDataType" :formData="formData"></toolView>
    </div>
    <!-- 小工具 -->
  </div>
</template>

<script>
import { Toast, ImagePreview } from 'vant'
import {
  getCargoTransportationInfoAc,
  getCompanyInfo,
  t_getHs_siji_tongxing,
  updateWorkerSh,
  getQyBaInfo,
  findgkList
} from '../../api/gov/home/index'
import { areaList } from '@vant/area-data'
import infoView from './compenent/info.vue'
import toolView from './compenent/tool.vue'
// import moment from 'moment'
export default {
  components: {
    infoView, // 基本信息
    toolView // 小工具
  },
  props: {},
  data () {
    return {
      taxOutpost: '',
      taxOutpostcolumns: [],
      showTaxOutpost: false, // 关卡显示或隐藏
      formDataType: false,
      active: '1',
      message: '',
      radio: '1',
      isolation: '', // 勾选隔离
      isInAndOuts: '',
      areaList,
      formData: {
        worker_type: '',
        peerList: [
          {
            passenger_name: '张三',
            passenger_cardno: '211422199711257613',
            passenger_tel: '12520437366',
            quguo_high_risk: '1',
            checkBtnTxt: '身份核验'
          }
        ]
      },
      resultsData: {
        hscy: '1', // 核酸采样
        temperature: '1', // 体温
        type: '1', // 冷链 非冷链
        worker_jkzm: '1', // 健康证明

        familyMembers: '', // 居家隔离家属姓名
        familyMembersPhone: '', // 居家隔离家属电话

        concentratedType: '0', // 集中隔离原因
        concentratedTw: '' // 集中隔离体温
      },
      results: {
        hesuan_result1: '', // 结果
        hesuan_result: '', // 结果
        hesuan_detail: '' // 详情
      }, // 获取到的核酸检测结果
      xcData: {
        quguo_high_risk: ''
      }, // 风险地区结果
      projectNameValue: '',
      projectNameValue1: '',
      projectNameValue2: '',
      showCategory: false,
      showCategory1: false,
      categoryArr: [
        {
          value: '1',
          lable: '体温正常'
        },
        {
          value: '2',
          lable: '体温异常'
        }
      ],
      categoryArr1: [
        {
          value: '1',
          lable: '冷链'
        },
        {
          value: '2',
          lable: '非冷链'
        }
      ],
      categoryArr3: [ // 车两类别
        {
          value: '1',
          lable: '小型轿车'
        },
        {
          value: '2',
          lable: '客运车辆'
        },
        {
          value: '3',
          lable: '货车'
        },
        {
          value: '4',
          lable: '特种车辆'
        }
      ],
      projectListArr: [
        {
          value: '1',
          lable: '蓝色'
        },
        {
          value: '2',
          lable: '黄色'
        },
        {
          value: '3',
          lable: '黑色'
        },
        {
          value: '4',
          lable: '白色'
        },
        {
          value: '5',
          lable: '绿色'
        },
        {
          value: '9',
          lable: '其他'
        }
      ],
      leaveTimeArr: [
        {
          value: '1',
          lable: '当天离沈'
        },
        {
          value: '2',
          lable: '在沈过夜'
        },
        {
          value: '3',
          lable: '空车返沈'
        }
      ],
      columns: [
        {
          'code': 'LM00001',
          'name': '和平区'
        },
        {
          'code': 'LM00002',
          'name': '沈河区'
        },
        {
          'code': 'LM00003',
          'name': '大东区'
        },
        {
          'code': 'LM00004',
          'name': '皇姑区'
        },
        {
          'code': 'LM00005',
          'name': '铁西区'
        },
        {
          'code': 'LM00006',
          'name': '浑南区'
        },
        {
          'code': 'LM00007',
          'name': '于洪区'
        },
        {
          'code': 'LM00008',
          'name': '沈北新区'
        },
        {
          'code': 'LM00009',
          'name': '苏家屯区'
        },
        {
          'code': 'LM00010',
          'name': '辽中区'
        },
        {
          'code': 'LM00011',
          'name': '康平县'
        },
        {
          'code': 'LM00012',
          'name': '法库县'
        },
        {
          'code': 'LM00013',
          'name': '新民市'
        }
      ]
    }
  },
  async mounted () {
    this.isInAndOuts = this.$route.query.value
    console.log(this.areaList, '地区')
    console.log('this.$route.query.worker_type', this.$route.query.worker_type)
    this.formDataType = false
    // return
    Toast.loading({
      message: '加载中...',
      forbidClick: true,
      duration: 10000
    })
    const res = await findgkList()
    this.taxOutpostcolumns = res.data.data.map(i => {
      return { lable: i.gk, value: i.id }
    })
    getCargoTransportationInfoAc({ driver_cardno: this.$route.query.cardNo, arrive_type_one: this.$route.query.value }).then(res => {
      console.log('t1', res)
      if (res.data.errcode != 0) {
        Toast.fail(res.data.errmsg)
        const TIME = setTimeout(() => {
          this.$router.go(-1)
          clearTimeout(TIME)
        }, 1500)
      }
      try {
        var tbox = {
          siji_info: {},
          tongxing_info_list: {}
        }
        if (res.data.data.gk_code) {
          console.log(this.taxOutpostcolumns, 'taxOutpostcolumns')
          console.log(res.data.data.gk_code, 'res.data.data.gk_code')
          this.taxOutpost = this.taxOutpostcolumns.find(i => i.value == res.data.data.gk_code).lable
          console.log(this.taxOutpost, 'this.taxOutpost')
        }
        if (res.data.data.driver_name) {
          tbox.siji_info.name = res.data.data.driver_name
        }
        if (res.data.data.driver_cardno) {
          tbox.siji_info.card_no = res.data.data.driver_cardno
        }
        if (res.data.data.peerList && res.data.data.peerList.length > 0) {
          var t_arr = []
          for (var i = 0; i < res.data.data.peerList.length; i++) {
            var t_obj = {}
            if (res.data.data.peerList[i].passenger_name) {
              t_obj.name = res.data.data.peerList[i].passenger_name
            }
            if (res.data.data.peerList[i].passenger_name) {
              t_obj.card_no = res.data.data.peerList[i].passenger_cardno
            }
            t_arr.push(t_obj)
          }
        }
        t_getHs_siji_tongxing(tbox).then(res => {
          console.log('tbox', res)
        })
      } catch (err) {
        console.error(err)
      }

      // const fr = ['jck_qd', 'jck_jyzm', 'hs_zm', 'xs_zm']
      // fr.forEach(i => {
      //   if (res.data.data.coldchainList[0][i].indexOf(',') === -1) {
      //     res.data.data.coldchainList[0][i] = [res.data.data.coldchainList[0][i]]
      //   } else {
      //     res.data.data.coldchainList[0][i] = res.data.data.coldchainList[0][i].split(',')
      //   }
      // })
      // 车辆类别
      if (res.data.data.cheliang_type) {
        res.data.data.cheliang_type_name = this.categoryArr3.find(e => e.value == res.data.data.cheliang_type).lable // 车辆类别
      }
      if (res.data.data.chepai_color) {
        res.data.data.chepai_color_name = this.projectListArr.find(e => e.value == res.data.data.chepai_color).lable // 车牌颜色
      }
      if (res.data.data.zssj) {
        res.data.data.zssj_name = this.leaveTimeArr.find(e => e.value == res.data.data.zssj).lable // 在沈时间
      }
      if (res.data.data.dsq) {
        res.data.data.dsqName = this.columns.find(e => e.code == res.data.data.dsq).name // 到沈区域
      }
      if (res.data.data.hesuan_result && res.data.data.hesuan_detail) {
        res.data.data.hesuan_result1 = res.data.data.hesuan_result + '(' + res.data.data.hesuan_detail + ')'
      } else {
        res.data.data.hesuan_result1 = '国家核酸检测接口请求失败'
      }
      res.data.data.origin = ''
      for (let i in this.areaList.province_list) {
        if (res.data.data.cfd_s == i) {
          res.data.data.origin = this.areaList.province_list[i]
        }
      }
      for (let i in this.areaList.city_list) {
        if (res.data.data.cfd_city == i) {
          res.data.data.origin = res.data.data.origin + ',' + this.areaList.city_list[i]
        }
      }
      res.data.data.peerList.map((v) => {
        v.checkBtnTxt = '核验身份'
        if (v.hesuan_result && v.hesuan_detail) {
          v.hesuan_result1 = v.hesuan_result + '(' + v.hesuan_detail + ')'
        } else {
          v.hesuan_result1 = '国家核酸检测接口请求失败'
        }
        return v
      })
      // res.data.data.goodsList.map((v) => {
      //   if (v.ascription_code) {
      //     v.ascription_code_name = this.columns.find(e => e.code == v.ascription_code).name
      //   }
      // })
      // 卫健委时 交通未审核清空 公安清空
      if (this.$route.query.worker_type == 'WJ') {
        if (!res.data.data.worker_jt) {
          this.resultsData.type = ''
        }
      }
      // 交通时局 交通未审核清空 公安清空
      if (this.$route.query.worker_type == 'JT') {
        if (!res.data.data.worker_wj) {
          this.resultsData.hscy = ''
          this.resultsData.temperature = ''
          this.radio = ''
        }
      }
      // 公安局 交通未审核清空 公安清空
      if (this.$route.query.worker_type == 'GA') {
        if (!res.data.data.worker_wj) {
          this.resultsData.hscy = ''
          this.resultsData.temperature = ''
          this.radio = ''
        }
        if (!res.data.data.worker_jt) {
          this.resultsData.type = ''
        }
      }
      this.formData = res.data.data
      this.formData.worker_type = this.$route.query.worker_type
      this.formDataType = true

      // this.trip.vehicleNo = res.data.data.car_number
      // this.trip.vehicleColor = res.data.data.chepai_color
      // this.projectNameValue2 = { lable: res.data.data.chepai_color_name }

      // 用车牌号查询是入沈还是返沈
      if (this.isInAndOuts != 1) { // 不是出沈时候 判断
        getCompanyInfo({ car_number: res.data.data.car_number }).then(req => {
          console.log(req, '车牌号改变 判断是否是返沈 入沈')
          // 1.出沈 2.入沈 3.返沈
          this.isInAndOuts = req.data.data.id ? 3 : 2
          console.log(this.isInAndOuts)
        })
      }
      Toast.clear()
    })
  },
  computed: {},
  methods: {
    // 关卡事件
    onTaxOutpost (value) {
      this.taxOutpost = value.lable
      this.showTaxOutpost = false
    },
    preview (img) {
      ImagePreview([img])
    },
    // 核验同行人
    checkBtn1 (e) {
      this.formData.peerList = e
      console.log('e 核验', e)
    },
    async submit () {
      // if (this.formData.worker_type == 'GA') {
      //   if (!this.formData.worker_jt) {
      //     Toast.success('交通局未审核')
      //     return
      //   }
      //   if (!this.formData.worker_wj) {
      //     Toast.success('卫健委未审核')
      //     return
      //   }
      // }
      // 只有交通局的时候判断企业备案
      if (this.formData.worker_type == 'JT') {
        const obj = {
          car_number: this.formData.car_number,
          driver_cardno: this.formData.driver_cardno,
          arrive_time: this.formData.arrive_time
        }
        const data = await getQyBaInfo(obj)
        if (data.data.errcode == 0) {
          this.$dialog.confirm({
            message: '已匹配到收货人信息',
            showConfirmButton: true,
            showCancelButton: true,
            cancelButtonText: '返回'
          }).then(() => {
            // on confirm
            this.nextTo()
          }).catch(() => { })
        } else {
          this.$dialog.confirm({
            message: '未匹配到收货人备案信息',
            showConfirmButton: false,
            showCancelButton: true,
            cancelButtonText: '返回'
          }).then(() => {
            this.nextTo()
          }).catch(() => {})
        }
      } else {
        this.nextTo()
      }
    },
    nextTo () {
      Toast.loading({
        message: '加载中...',
        forbidClick: true,
        duration: 10000
      })
      // if (this.resultsData.hscy == '' || this.resultsData.hscy == null) {
      //   this.$dialog.alert({
      //     message: `请选择现场核酸采样`
      //   })
      //   return
      // }
      // if (this.resultsData.temperature == '' || this.resultsData.temperature == null) {
      //   this.$dialog.alert({
      //     message: `请选择体温状况`
      //   })
      //   return
      // }
      // if (this.radio == '' || this.radio == null) {
      //   this.$dialog.alert({
      //     message: `请选择管控处置情况`
      //   })
      //   return
      // }
      if (this.formData.worker_type == 'GA') {
        const infoType = this.formData.peerList.find(e => e.infoType)
        if (infoType && infoType.infoType) {
          this.$dialog.alert({
            message: `同行人(${infoType.passenger_name})未注册盛事通,请同行人员注册盛事通后再进行提交`
          })
          return
        }
      }
      if (this.taxOutpost == '') {
        this.$toast.fail('请选择关卡')
        return
      }
      updateWorkerSh({
        type: this.radio,
        reason: this.message,
        arrive_type_one: this.$route.query.value,
        worker_type: this.$route.query.worker_type,
        register_code: this.formData.register_code,
        worker_jkzm: this.resultsData.worker_jkzm, // 健康证明
        worker_czfs: this.radio, // 处置方式
        worker_reason: this.message, // 劝返原因
        worker_glfs: this.isolation, // 隔离方式
        worker_jsxm: this.resultsData.familyMembers, // 家属姓名
        worker_jsdh: this.resultsData.familyMembersPhone, // 家属姓名
        worker_jzglyy: this.resultsData.concentratedType, // 集中隔离原因
        worker_tw: this.resultsData.concentratedTw, // 送达体温
        worker_hs_name: this.resultsData.name, // 姓名 核酸
        worker_hs_cardno: this.resultsData.card, // 身份证号 核酸
        worker_hs_result: this.results.hesuan_result, // 核酸结果
        worker_hs_detail: this.results.hesuan_detail, // 核酸结果详情
        worker_xc: this.xcData.quguo_high_risk, // 行程结果
        worker_xchs: this.resultsData.hscy, // 现场核酸
        worker_xctw: this.resultsData.temperature, // 现场体温
        worker_xchwjy: this.resultsData.type, // 现场验货
        gk_code: this.taxOutpostcolumns.find(i => i.lable === this.taxOutpost).value// 关卡
      }).then(res => {
        console.log(res)
        Toast.clear()
        if (res.data.errcode == 0) {
          Toast.success('审核成功')
          const TIME = setTimeout(() => {
            this.$router.go(-1)
            clearTimeout(TIME)
          }, 1500)
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>
.audit {
  .title {
    padding: 0.533rem 0.853rem;
    font-size: 0.747rem;
    color: #646566;
  }
  /deep/.van-field__label {
    width: 10em;
    display: flex;
    align-items: center;
  }
  .img_list {
    margin: 20px 0.853rem;
    display: flex;
    img {
      width: 120px;
      height: 120px;
      margin-right: 20px;
    }
  }
}
.czInfo {
  height: 80px;
  font-size: 32px;
  //font-weight: bold;
  //color: white;
  //background-color: #58be6a;
  background-color: #eee;
  display: flex;
  align-items: center;
  div {
    width: 690px;
    margin: 0 auto;
  }
}
.nucleicAcid {
  width: 690px;
  margin: 40px auto;
  border-radius: 20px;
  overflow: hidden;
  box-sizing: border-box;
  //border: 1px solid #DDEEE3;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  .title {
    text-align: center;
    font-size: 28px;
    color: white;
    background-color: #58be6a;
  }
}
.btn {
  width: 150px;
}
.field {
  width: 690px;
  height: 90px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #ebedf0;
  margin: 0 auto;
  box-sizing: border-box;
  .label {
    font-size: 28px;
    color: #646566;
    flex-shrink: 0;
  }
  .text {
    font-size: 28px;
    color: #646566;
    display: flex;
    align-items: center;
    .icon {
      width: 15px;
      height: 15px;
      border-radius: 15px;
      background-color: #58be6a;
      flex-shrink: 0;
      margin-right: 5px;
    }
    .icon1 {
      width: 15px;
      height: 15px;
      border-radius: 15px;
      flex-shrink: 0;
      background-color: red;
      margin-right: 5px;
    }
    .value {
      color: #58be6a;
    }
    .value1 {
      color: red;
    }
  }
}
.concentrated /deep/.van-field__label {
  width: 6.3em;
}
//.concentrated /deep/ .van-radio--horizontal{
//  margin-top: 10px;
//  margin-left: 160px;
//}
.btnClass {
  width: 95%;
  margin: 20px 18px;
}
.mapOut {
  width: 690px;
  height: 1000px;
  background-color: white;
  .title {
    height: 60px;
    line-height: 60px;
    font-size: 32px;
    text-align: center;
  }
}
.trip /deep/.van-field__label {
  width: 9em;
}
</style>
